package com.bite;

public class Sort {
    // 插入排序
    public static void insertSort(int[] array){
        // write code  here
        for(int i = 1; i < array.length; i++){
            int k = i;
            for(int j = k - 1; j >= 0; j--){
                if(array[j] > array[k]){
                    int temp = array[j];
                    array[j] = array[k];
                    array[k] = temp;
                    k--;
                }
            }
        }
    }
    // 希尔排序
    public static void shellSort(int[] array){
        //write code  here
        int gap = array.length;
        while(gap > 1){
            gap/=2;
            shell(array, gap);
        }
    }

    private static void shell(int[] array, int gap) {
        for(int i = gap; i < array.length; i+=gap){
            int temp = array[i];
            int j = i - gap;
            for(; j >= 0; j-=gap){
                if(array[j] > array[i]){
                    array[j+gap] = array[j];
                }else{
                    break;
                }
            }
            array[j + gap] = temp;
        }
    }

}
